$(document).ready(function() {
	showClubValue();
});
function showClubValue() {
	$.ajax({
		url : localhost + "memorabilia/getMNameByUserId",
		dataType : "jsonp",
		jsonp : "jsonpCallback",
		success : function(data) {
			var str = "";
			for (var int = 0; int < data.length; int++) {
				str += '<option value ="' + data[int].club_id + '">'
						+ data[int].club_name + '</option>'
			}
			$("#clubNameValue").html(str);
		}
	});
}
$("#activitiesBtn").click(
		function() {
			var clubId = document.getElementById("clubNameValue").value;
			var title = $.trim($('#title').val());
			var content = $.trim($('#content').val());
			var clubActivitiesBeginDate = new Date($.trim($(
					'#clubActivitiesBeginDate').val()));
			var clubActivitiesEndDate = new Date($.trim($(
					'#clubActivitiesEndDate').val()));
			var today = new Date();

			if (title == "" || content == "") {
				$('#error').text('活动信息不能为空').show();
				return;
			} else if (clubId == "") {
				$('#error').text('请选择一个俱乐部').show();
				return;
			}  else if (clubActivitiesBeginDate > clubActivitiesEndDate) {
				$('#error').text('开始时间不能晚于结束时间').show();
				return;
			} else if (clubActivitiesBeginDate < today) {
				$('#error').text('请选择一个还没有开始的时间').show();
				return;
			} else {
				$.ajax({
					url : localhost + "clubActivities/addClubActivities",
					dataType : "jsonp",
					data : {
						clubActivitiesTitle : title,
						clubActivitiesContent : content,
						clubId : clubId,
						clubActivitiesBeginDate : clubActivitiesBeginDate.getTime(),
						clubActivitiesEndDate : clubActivitiesEndDate.getTime()
					},
					jsonp : "jsonpCallback",
					success : function(data) {
						if (data <= 0) {
							$("#error").html("*添加失败*");
						} else {
							$("#error").html("*添加成功*");
							window.location.href = "recentActivities.shtml";
						}
					}
				});
			}
		});